home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************************
- *
- *_Title CLEMDCMP_MENU - Insert program menus and obtain user input
- *
- *_Args Type Variable I/O Description
- *_Parm char *opt I Menu option. If opt=NEW, the current menu
- * bar will be removed and the program specific
- * menu bar will be in-stalled. User input
- * will be obtained until either the Run option
- * or the Quit option is clicked on in the File
- * menu. If opt=OLD, the current (program
- * specific) menu bar will be removed and the
- * previous menu bar will be reinstalled.
- *
- *_Desc Clemdcmp_menu will insert the program specific menus into the menu bar
- * and obtain the user input.
- *
- *_Hist Unknown Janet Barrett, USGS, Flagstaff Original Version
- * Aug 12 1994 Tracie Sucharski, Adapted for the clementine decompression
- * software
- *
- ***********************************************************************************/
-
- /********************
- * Standard C includes
- *********************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- /***************************
- * Macintosh toolbox includes
- ****************************/
- #include <Packages.h>
-
- /*****************
- * Global variables
- ******************/
- extern struct {
- char prgnam[9];
- char hlpfil[13];
- char infile[128];
- char outfile[128];
- char img;
- char format;
- } clemargs;
-
- void clemdcmp_menu (char *opt)
- {
- static Handle mbar,ombar;
- SFReply replyi,replyo;
- MenuHandle applemenu,filemenu,parammenu,param1menu,param2menu;
- EventRecord TheEvent;
- Boolean nxtevt;
- WindowPtr theWin;
- short int thePart;
- SFTypeList types;
- long int menuChoice;
- int iflg = 0;
- int oflg = 0;
- int theMenu,theItem;
- Point where = {100,50};
- extern long int resnum;
- long int winres = 440;
- long int vscres = 441;
- char *opt1 = "NEW";
- char *opt2 = "OLD";
- long int istr;
-
- void errmsg();
- void get_filename();
- void scroll();
-
- if (*opt == *opt1) {
- replyi.good = 0;
- replyo.good = 0;
-
- /*********************************
- * Get a handle to the old menu bar
- **********************************/
- ombar = GetMenuBar();
-
- /*********************************
- * Get a handle to the new menu bar
- **********************************/
- mbar = GetNewMBar(128);
-
- /*******************************************
- * Make the new menu bar the current menu bar
- ********************************************/
- SetMenuBar(mbar);
-
- /*******************************
- * Get a handle to the apple menu
- ********************************/
- applemenu = GetMenu(129);
-
- /******************************
- * Get a handle to the File menu
- *******************************/
- filemenu = GetMenu(130);
-
- /************************************
- * Get a handle to the Parameters menu
- *************************************/
- parammenu = GetMenu(131);
- param1menu = GetMenu(1);
- param2menu = GetMenu(2);
-
- /**************************************
- * Insert the apple menu in the menu bar
- ***************************************/
- InsertMenu(applemenu,0);
-
- /*************************************
- * Insert the File menu in the menu bar
- **************************************/
- InsertMenu(filemenu,0);
-
- /*******************************************
- * Insert the Parameters menu in the menu bar
- ********************************************/
- InsertMenu(parammenu,0);
- InsertMenu(param1menu,-1);
- InsertMenu(param2menu,-1);
-
- /***********************************
- * Disable all appropriate menu items
- ************************************/
- DisableItem(filemenu,3);
-
- /**********************
- * Draw the new menu bar
- ***********************/
- DrawMenuBar();
- CheckItem(param1menu,1,true);
- CheckItem(param2menu,1,true);
-
- /********************
- * Handle a menu event
- *********************/
-
- /***************************
- * Get an event from the user
- ****************************/
- theMenu = 0;
- theItem = 0;
- while (theMenu != 130 | theItem != 3) {
- nxtevt = GetNextEvent(everyEvent,&TheEvent);
-
- /******************
- * Process the event
- *******************/
- if (TheEvent.what == mouseDown || TheEvent.what == keyDown) {
-
- /*********************************************************************
- * Determine which part of which window the mouse button was pressed in
- **********************************************************************/
- thePart = FindWindow(TheEvent.where,&theWin);
-
- /******************************************************************
- * Process the event if the mouse button was pressed in the menu bar
- *******************************************************************/
- if (thePart == inMenuBar || (TheEvent.modifiers & cmdKey)) {
- if (thePart == inMenuBar && TheEvent.what == mouseDown) {
- menuChoice = MenuSelect(TheEvent.where);
- }
- else {
- menuChoice = MenuKey(TheEvent.message & charCodeMask);
- }
-
- if (menuChoice != 0) {
- theMenu = HiWord(menuChoice);
- theItem = LoWord(menuChoice);
-
- switch (theMenu) {
- case 129: /* Apple Menu */
- switch (theItem) {
- case 1:
- HiliteMenu(0);
- DisableItem(applemenu,0);
- DisableItem(filemenu,0);
- DisableItem(parammenu,0);
- DrawMenuBar();
- scroll(clemargs.hlpfil,clemargs.prgnam,&winres,&vscres);
- EnableItem(applemenu,0);
- EnableItem(filemenu,0);
- EnableItem(parammenu,0);
- DrawMenuBar();
- break;
- }
- break;
- case 130: /* File Menu */
- switch (theItem) {
- case 1:
- SFGetFile(where,"\p",NULL,-1,types,NULL,&replyi);
- iflg = 1;
- if (oflg == 1)
- EnableItem(filemenu,3);
- HiliteMenu(0);
- break;
- case 2:
- SFPutFile(where,"\pOutput decompressed Clementine File",c2pstr(clemargs.outfile),
- NULL,&replyo);
- get_filename(replyo,clemargs.outfile);
- istr = strlen(clemargs.outfile);
- while ((clemargs.outfile[istr] != ':') && (istr > -1))
- istr = istr -1;
- if (istr > -1)
- strcpy(&(clemargs.outfile[0]),&(clemargs.outfile[istr+1]));
- oflg = 1;
- if (iflg == 1)
- EnableItem(filemenu,3);
- HiliteMenu(0);
- break;
- case 3:
- get_filename(replyi,clemargs.infile);
- get_filename(replyo,clemargs.outfile);
- oflg = 1;
- if (iflg == 1)
- EnableItem(filemenu,3);
- HiliteMenu(0);
- break;
- case 5:
- clemdcmp_menu("OLD");
- exit(0);
- break;
- }
- break;
- case 2: /* Output File Type */
- switch (theItem) {
- case 1:
- CheckItem(param2menu,1,true);
- CheckItem(param2menu,2,false);
- clemargs.img = 'i';
- HiliteMenu(0);
- break;
- case 2:
- CheckItem(param2menu,1,false);
- CheckItem(param2menu,2,true);
- clemargs.img = 'b';
- HiliteMenu(0);
- break;
- }
- break;
- case 1: /* Output File format */
- switch (theItem) {
- case 1:
- CheckItem(param1menu,1,true);
- CheckItem(param1menu,2,false);
- CheckItem(param1menu,3,false);
- CheckItem(param1menu,4,false);
- clemargs.format = 'n';
- HiliteMenu(0);
- break;
- case 2:
- CheckItem(param1menu,1,false);
- CheckItem(param1menu,2,true);
- CheckItem(param1menu,3,false);
- CheckItem(param1menu,4,false);
- clemargs.format = 'p';
- HiliteMenu(0);
- break;
- case 3:
- CheckItem(param1menu,1,false);
- CheckItem(param1menu,2,false);
- CheckItem(param1menu,3,true);
- CheckItem(param1menu,4,false);
- clemargs.format = 'g';
- HiliteMenu(0);
- break;
- case 4:
- CheckItem(param1menu,1,false);
- CheckItem(param1menu,2,false);
- CheckItem(param1menu,3,false);
- CheckItem(param1menu,4,true);
- clemargs.format = 't';
- HiliteMenu(0);
- break;
- }
- break;
- }
- }
- }
- }
- }
- }
- else if (*opt == *opt2) {
-
- /********************************************************
- * Release the resources that are occupied by the new menu
- *********************************************************/
- ReleaseResource(mbar);
-
- /*************************
- * Restore the old menu bar
- **************************/
- SetMenuBar(ombar);
- }
- }
-
-
-
-
-
-
-
-